package com.wx.activitys.drp.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wx.activitys.drp.mapper.PlatfromMapper;
import com.wx.activitys.drp.mapper.ProfitMapper;
import com.wx.activitys.drp.mapper.RoleMapper;
import com.wx.activitys.drp.model.BPlatfrom;
import com.wx.activitys.drp.model.BProfit;
import com.wx.activitys.drp.model.BRole;
import com.wx.activitys.drp.service.DigitalSignature;
import com.wx.activitys.drp.service.PlatfromService;


@Service("/PlatfromService")
public class PlatfromServiceImpl implements PlatfromService {
    @Autowired
    PlatfromMapper platfromMapper;
    @Autowired
    ProfitMapper profitMapper;
    @Autowired
    RoleMapper rl;
    

	@Override
	public List<BPlatfrom> queryPageList(BPlatfrom entity) {
		
		return platfromMapper.queryPageList(entity);
	}

	@Override
	public int selectCount(BPlatfrom entity) {
		// TODO Auto-generated method stub
		return platfromMapper.selectCount(entity);
	}

	@Override
	public int insert(BPlatfrom entity) {
		String id = DigitalSignature.getUUID();
		entity.setId(id);
		entity.setCreateTime(new Date());
		List<BProfit> list = new ArrayList<>();
		List<BRole> ro = rl.findAll();
		list.clear();
		for (BRole bRole : ro) {
			BProfit bs = new BProfit();
			bs.setRoleKey(bRole.getRoleKey());
			bs.setPaltformId(id);
			bs.setValue(1.0);
            list.add(bs);				
		}
		profitMapper.addBatch(list);		
		return platfromMapper.insert(entity);
	}

	@Override
	public int update(BPlatfrom entity) {
		// TODO Auto-generated method stub
		return platfromMapper.update(entity);
	}

	@Override
	public BPlatfrom selectEntity(BPlatfrom entity) {
		// TODO Auto-generated method stub
		return platfromMapper.selectEntity(entity);
	}

	@Override
	public int delete(BPlatfrom entity) {
		// TODO Auto-generated method stub
		return platfromMapper.delete(entity);
	}

	@Override
	public List<BPlatfrom> queryProfitsPageList(BPlatfrom entity) {
		// TODO Auto-generated method stub
		return platfromMapper.queryProfitsPageList(entity);
	}
	
	@Override
	public List<BPlatfrom> findByEntity(BPlatfrom entity) {
		// TODO Auto-generated method stub
		return platfromMapper.findByEntity(entity) ;
	}


	@Override
	public List<BPlatfrom> queryALL(BPlatfrom entity) {
		// TODO Auto-generated method stub
		return platfromMapper.queryALL(entity);
	}



}
